<template>
  <d2-container>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="queryItems[0].value" :placeholder="$t('name')" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t('query') }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="$hasPermission('sys:lawyer:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="$hasPermission('sys:lawyer:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      size="mini"
      v-loading="dataListLoading"
      :data="dataList"
      border
      stripe
      @selection-change="dataListSelectionChangeHandle"
      @sort-change="dataListSortChangeHandle"
      style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50"/>
      <el-table-column prop="name" :label="$t('name')" header-align="center" align="center"/>
      <el-table-column prop="lawOfficeName" :label="$t('lawyer.lawOfficeName')" header-align="center" align="center"/>
      <el-table-column prop="qualificationCode" :label="$t('lawyer.qualificationCode')" header-align="center" align="center"/>
      <el-table-column prop="qualificationGetDate" :label="$t('lawyer.qualificationGetDate')" header-align="center" align="center" :formatter="dateFormat" />
      <el-table-column prop="phone" :label="$t('phone')" header-align="center" align="center"/>
      <el-table-column prop="birthday" :label="$t('birthday')" header-align="center" align="center" :formatter="dateFormat" />
      <el-table-column prop="remark" :label="$t('remark')" header-align="center" align="center"/>
      <el-table-column prop="createTime" :label="$t('createTime')" sortable="custom" header-align="center" align="center" width="180"/>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template slot-scope="scope">
          <el-button v-if="$hasPermission('sys:lawyer:update')" type="text" size="mini" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
          <el-button v-if="$hasPermission('sys:lawyer:delete')" type="text" size="mini" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"/>
    <!-- 分页 -->
    <el-pagination
      slot="footer"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="pageSizeChangeHandle"
      @current-change="pageCurrentChangeHandle">
    </el-pagination>
  </d2-container>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './lawyer-add-or-update'
export default {
  mixins: [ mixinViewModule ],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/lawyer/page',
        getDataListIsPage: true,
        deleteURL: '/lawyer/delete',
        deleteIsBatch: true
      },
      dataForm: {

      },
      queryItems: [
        {
          field: 'name',
          as: 'LIKE',
          value: ''
        }
      ],
      order: 'ASC',
      orderField: 'createTime'
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    dateFormat:function(row,column) {
      const dateStr = row[column.property]
      if (dateStr != null) {
        const dateMat = new Date(dateStr);
        const year = dateMat.getFullYear();
        const month = dateMat.getMonth() + 1;
        const day = dateMat.getDate();
        const hh = dateMat.getHours();
        const mm = dateMat.getMinutes();
        const ss = dateMat.getSeconds();
        // const timeFormat = year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss;
        // const timeFormat = year + "-" + month + "-" + day;
        let timeFormat = year+'-'+ (month<10?'0'+month:month)+'-'+ (day<10?'0'+day:day);
        return timeFormat;
      }
    }
  }
}
</script>
